/**
 * Created by haocongshun on 2016/10/12.
 */
var contextPath = "";
var ue = "";
$(function () {
    contextPath = getContextPath();
    ue = UE.getEditor('editor');
    var content = getIntroduction();
    enter();
    cancel();
    ue.ready(function() {
        //设置编辑器的内容
        ue.setContent(content);
    });
});
function enter() {
    $("#enter").click(function () {
        ue.ready(function() {
            //获取html内容，返回: <p>hello</p>
            var html = ue.getContent();
            //获取纯文本内容，返回: hello
            var txt = ue.getContentTxt().substring(0,200);
            setIntroduction(html,txt);
        });
    });
}
function cancel() {
    $("#cancel").click(function () {
        window.history.back(-1);
    });
    
}
function getIntroduction() {
    var url = contextPath+"/PersonalData/getIntroduction.press"
    var data = {};
    $.ajaxSetup({
        async : false
    });
    var content = '';
    $.post(url,data,function (result) {
        content = result.content;
    },"json");
    return content;
}
function setIntroduction(content,introduction) {
    var url = contextPath+"/PersonalData/setIntroduction.press"
    var data = {};
    data.content=content;
    data.introduction=introduction;
    $.post(url,data,function (result) {
        if(result.Msg=true){
            alert("保存成功！");
        }else {
            alert("保存出错！稍后再试！")
        }
    },"json");
}
